package com.turman.demo;

import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
import android.view.LayoutInflater;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.airbnb.lottie.LottieAnimationView;
import com.turman.builibrary.refresh.BOverview;

public class BLottieOverView extends BOverview {
    private LottieAnimationView mAnimationView;

    private int lastScrollY=-1;

    public BLottieOverView(@NonNull Context context) {
        super(context);
    }

    public BLottieOverView(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public BLottieOverView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    public void init() {
        LayoutInflater.from(getContext()).inflate(R.layout.refresh_lottie_overview, this,true);
        mAnimationView = findViewById(R.id.lottie_view);
    }

    @Override
    protected void onScroll(int scrollY, int pullRefreshHeight) {
        if (scrollY>lastScrollY) {
            mAnimationView.setFrame(getBottom() / 10);
        }
        lastScrollY = scrollY;
    }

    @Override
    protected void onVisible() {

    }

    @Override
    public void onOver() {

    }

    @Override
    public void onRefresh() {
        mAnimationView.playAnimation();
    }

    @Override
    public void onRefreshFinished() {
        mAnimationView.cancelAnimation();
    }
}
